﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.SharePoint;

namespace GetAllReusableAcls
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("begin...");

            try
            {
                using (SPSite _site = new SPSite("http://SharePoint"))
                {
                    try
                    {
                        IDictionary<Guid, SPReusableAcl> AllReusableAcls;
                        AllReusableAcls = _site.GetAllReusableAcls();

                        foreach (KeyValuePair<Guid, SPReusableAcl> kvp in AllReusableAcls)
                        {
                            SPReusableAcl spRACL = kvp.Value;
                            SPBasePermissions spBase = _site.GetEffectiveRightsForAcl(spRACL);

                            System.Console.WriteLine(string.Format("{0}: {1}", kvp.Key, spBase));
                        }
                        System.Console.WriteLine("Count of Values in ACL: {0}", AllReusableAcls.Values.Count);
                    }
                    catch (Exception ex)
                    {
                        System.Console.WriteLine("Error: " + ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Console.WriteLine("Error: " + ex.Message);
            }
            finally
            {
                Console.WriteLine("completed.  Press ENTER key to continue...");
                Console.ReadLine();
            }
        }
    }
}
